class Solution(object):
    def champagneTower(self, poured, query_row, query_glass):
        """
        :type poured: int
        :type query_row: int
        :type query_glass: int
        :rtype: float
        """
        n = query_row * (query_row + 1) // 2 + query_glass + 1
        p = [0] * n
        p[0] = poured
        index = 0
        step = 1
        c = 0
        while index < n:
            if p[index] >= 1:
                diff = p[index] - 1
                p[index] = 1
                if index + step < n:
                    p[index + step] += diff / 2
                if index + step + 1 < n:
                    p[index + step + 1] += diff / 2
            index += 1
            c += 1
            if c == step:
                step += 1
                c = 0
        return p[-1]


data = Solution()
poured = 5
query_row = 2
query_class = 1
print(data.champagneTower(poured, query_row, query_class))